package nav;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import conexion.ProxyIR;


import VO.ClienteVO;
import VO.SolicitudRodamientosVO;

/**
 * Servlet implementation class SolicRodObtenerCliente
 */
public class SolicRodObtenerCliente extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SolicRodObtenerCliente() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.sendRedirect(PagesNav.GENERARSOLICITUD);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.getSession().setAttribute("errmessage",null);
		String cuit=request.getParameter("cuit");
		SolicitudRodamientosVO srvo=null;
		ProxyIR cpr = ProxyIR.getInstance();
		ClienteVO cli = cpr.obtenerCliente(cuit);
	
		if(cli!=null)
		{
			srvo = new SolicitudRodamientosVO();
			srvo.setCliente(cli);
			request.getSession().setAttribute("sr_srvo",srvo);
			
			//traigo todos los rodamientos
			request.getSession().setAttribute("sr_rodamientos", cpr.obtenerRodamientos());
		}
		else
		{
			request.getSession().setAttribute("errmessage","No existe cliente con cuit:"+ cuit);
		}
		response.sendRedirect(PagesNav.GENERARSOLICITUD);
	}

}
